/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-6-17 下午5:52
 * Copyright (c) 2017. All rights reserved.
 */

package com.hack.eden.pdfreader.util;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hack.eden.pdfreader.R;

/**
 * Created by dqhl on 17/6/17.
 */
public class BottomBar extends RelativeLayout implements View.OnClickListener{

    private ImageView tabOneIv;
    private ImageView tabTwoIv;
    private ImageView tabThreeIv;

    private LinearLayout layoutTab1;
    private LinearLayout layoutTab2;
    private LinearLayout layoutTab3;

    private TextView tabTextView1;
    private TextView tabTextView2;
    private TextView tabTextView3;

    private ImageView currentSelectImage;


    public BottomBar(Context context) {
        this(context,null);
    }

    public BottomBar(Context context, AttributeSet attrs) {
        this(context, attrs,-1);
    }

    public BottomBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_bottom_bar,this);

        tabOneIv = (ImageView) findViewById(R.id.iv_tab_1);
        tabTwoIv = (ImageView) findViewById(R.id.iv_tab_2);
        tabThreeIv = (ImageView) findViewById(R.id.iv_tab_3);

        layoutTab1 = (LinearLayout) findViewById(R.id.ll_tab1);
        layoutTab2 = (LinearLayout) findViewById(R.id.ll_tab2);
        layoutTab3 = (LinearLayout) findViewById(R.id.ll_tab3);

        tabTextView1 = (TextView) findViewById(R.id.tv_tab_1);
        tabTextView2 = (TextView) findViewById(R.id.tv_tab_2);
        tabTextView3 = (TextView) findViewById(R.id.tv_tab_3);

        layoutTab1.setOnClickListener(this);
        layoutTab2.setOnClickListener(this);
        layoutTab3.setOnClickListener(this);

        tabOneIv.setSelected(true);
        currentSelectImage = tabOneIv;
    }

    private OnTabClickListener onTabClickListener;

    public void setOnTabClickListener(OnTabClickListener onTabClickListener){
        this.onTabClickListener = onTabClickListener;
    }

    public interface OnTabClickListener{
        void onTabClick(int position);
    }

    public void onClick(View view){
        currentSelectImage.setSelected(false);
        switch (view.getId()){
            case R.id.ll_tab1:
                if (this.onTabClickListener != null){
                    this.onTabClickListener.onTabClick(1);
                }
                tabTextView2.setTextColor(Color.BLACK);
                tabTextView3.setTextColor(Color.BLACK);
                tabTextView1.setTextColor(getResources().getColor(R.color.color_main));
                currentSelectImage = tabOneIv;
                break;
            case R.id.ll_tab2:
                if (this.onTabClickListener != null){
                    this.onTabClickListener.onTabClick(2);
                }
                tabTextView1.setTextColor(Color.BLACK);
                tabTextView3.setTextColor(Color.BLACK);
                tabTextView2.setTextColor(getResources().getColor(R.color.color_main));
                currentSelectImage = tabTwoIv;
                break;
            case R.id.ll_tab3:
                if (this.onTabClickListener != null){
                    this.onTabClickListener.onTabClick(3);
                }
                tabTextView1.setTextColor(Color.BLACK);
                tabTextView2.setTextColor(Color.BLACK);
                tabTextView3.setTextColor(getResources().getColor(R.color.color_main));
                currentSelectImage = tabThreeIv;
                break;
        }
        currentSelectImage.setSelected(true);
    }
}
